package luke4fun.wheresmymoney.util;

import java.util.Calendar;

public class DateUtil {
	
	public static long getTodayInMillis() {
		Calendar c = Calendar.getInstance();
		int year  = c.get(Calendar.YEAR);
		int month = c.get(Calendar.MONTH);
		int day   = c.get(Calendar.DAY_OF_MONTH);
		
		c.clear();
		c.set(year, month, day);
		
		return c.getTimeInMillis();
	}

	public static long getCurrentMonthInMillis() {
		Calendar c = Calendar.getInstance();
		int year  = c.get(Calendar.YEAR);
		int month = c.get(Calendar.MONTH);
		
		c.clear();
		c.set(year, month, 1);
		
		return c.getTimeInMillis();
	}
	
	public static long getNextMonthInMillis(long dateInMillis) {
		Calendar c = Calendar.getInstance();
		c.clear();
		c.setTimeInMillis(dateInMillis);
		c.set(c.get(Calendar.YEAR), c.get(Calendar.MONTH)+1, 1);
		
		return c.getTimeInMillis();
	}
	
	public static long getPrevMonthInMillis(long dateInMillis) {
		Calendar c = Calendar.getInstance();
		c.clear();
		c.setTimeInMillis(dateInMillis);
		c.set(c.get(Calendar.YEAR), c.get(Calendar.MONTH)-1, 1);
		
		return c.getTimeInMillis();
	}
}
